package ${packageStr};

import java.util.List;
import javax.annotation.Resource;
import ${managerType};
import ${serviceType};
import ${commandType};
import ${queryCommand};
import ${voType};
import com.winit.common.IdCommand;
import com.winit.common.IdListCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import com.winit.common.query.Page;
import com.winit.common.spi.SPIException;

/**
 * 
 * ${entityDesc}service服务类
 * 
 * @version 
 * <pre>
 * Author	Version		Date		Changes
 * ${author}    1.0  ${time} Created
 *
 * </pre>
 * @since 1.
 */
@Service("${lowerEntityName}Service")
public class ${entityName}ServiceImpl implements ${entityName}Service {

    private Logger        logger = LoggerFactory.getLogger(${entityName}ServiceImpl.class);

    @Resource
    private ${entityName}Manager ${lowerEntityName}Manager;

    @Override
    public ${entityName}Vo get${entityName}(IdCommand command) throws SPIException {
        Long id = command.getId();
        
        if (id == null) {
            logger.error("id不能为空");
            throw new SPIException("");
        }
        return ${lowerEntityName}Manager.get${entityName}(id);
    }

    @Override
    public Long create${entityName}(${entityName}Command command) throws SPIException {
        ${entityName}Vo vo = command.getVo();
        
        if (vo == null) {
            logger.error("vo不能为空");
            throw new SPIException("");
        }
        return ${lowerEntityName}Manager.create${entityName}(vo);
    }

    @Override
    public void delete${entityName}(IdCommand command) throws SPIException {
        Long id = command.getId();
        
        if (id == null) {
            logger.error("id不能为空");
            throw new SPIException("");
        }
        ${lowerEntityName}Manager.delete${entityName}(id);
    }

    @Override
    public void deleteBatch${entityName}(IdListCommand command) throws SPIException {
        List<Long> ids = command.getIdList();
        
        if (ids == null || ids.size() == 0) {
            logger.error("ids不能为空");
            throw new SPIException("");
        }
        ${lowerEntityName}Manager.deleteBatch${entityName}(ids);
    }

    @Override
    public void update${entityName}(${entityName}Command command) throws SPIException {
        ${entityName}Vo vo = command.getVo();
        
        if (vo == null) {
            logger.error("vo不能为空");
            throw new SPIException("");
        }
        ${lowerEntityName}Manager.update${entityName}(vo);
    }

    @Override
    public Page<${entityName}Vo> find${entityName}Page(${entityName}QueryCommand command) throws SPIException {
        ${entityName}Vo vo = command.getVo();
        PageVo pageVo = command.getPageVo();
        return ${lowerEntityName}Manager.find${entityName}Page(pageVo, vo);
    }

    @Override
    public List<${entityName}Vo> query${entityName}List(${entityName}QueryCommand command) throws SPIException {
        ${entityName}Vo vo = command.getVo();
        return ${lowerEntityName}Manager.query${entityName}List(vo);
    }
}
